//
//  TOCircleHead.m
//  X-Tribe
//
//  Created by Miss.Ou on 16/4/3.
//  Copyright © 2016年 Miss.Ou. All rights reserved.
//

#import "TOCircleHead.h"
#import "TOTipCollectionViewCell.h"

@interface TOCircleHead ()<UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UIScrollViewDelegate>


@property(nonatomic,strong)UICollectionView *collectionV;
@property(nonatomic,retain)UIPageControl *pageC;


@end

@implementation TOCircleHead

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createCollectionViewWith:frame];
    }
    
    return self;
}


#pragma mark - 创建collectionView
-(void)createCollectionViewWith:(CGRect)frame
{
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    
    self.collectionV = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:flowLayout];
    self.collectionV.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.collectionV];
    self.collectionV.showsHorizontalScrollIndicator = NO;
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    self.collectionV.pagingEnabled = YES;
    [self.collectionV registerClass:[TOTipCollectionViewCell class] forCellWithReuseIdentifier:@"tipCollectionViewCell"];
    [self createPageC];
    
    
}

-(void)createPageC
{
    //设置page
    self.pageC = [[UIPageControl alloc] init];
    self.pageC.backgroundColor = [UIColor clearColor];
    [self addSubview:self.pageC];
    
    [self.pageC mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self);
        make.height.mas_equalTo(30);
        make.left.mas_equalTo(100);
        make.right.mas_equalTo(-100);
    }];
    //设置未选中点得颜色
    self.pageC.pageIndicatorTintColor = [UIColor lightGrayColor];
    //设置选中小点颜色
    self.pageC.currentPageIndicatorTintColor = [UIColor whiteColor];
    self.pageC.alpha = 0.6;
    self.pageC.numberOfPages = 2;
    self.pageC.currentPage = 0;

}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 2;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return 8;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TOTipCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"tipCollectionViewCell" forIndexPath:indexPath];
    
    
    return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(SCREEN_WIDTH/4, 100);
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.circleHeadDelegate JumpToActivityView];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    self.pageC.currentPage = self.collectionV.contentOffset.x/SCREEN_WIDTH;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
